const path = require('path');
const { chromium } = require('playwright');

async function sample() {
  const browser = await chromium.launch({ headless: true });
  const context = await browser.newContext();
  const page = await context.newPage();
  const templatePath = path.join(__dirname, 'template.html');
  const params = new URLSearchParams({
    problem: 'P1001',
    title: 'A + B Problem',
    rid: '123456789',
    lang: 'C++17',
    time: '2025-01-01 12:00:00',
    code: `#include <bits/stdc++.h>\nusing namespace std;\nint main(){long long a,b;cin>>a>>b;cout<<a+b;}`
  });
  const url = 'file://' + templatePath.replace(/\\/g, '/') + '?' + params.toString();
  await page.goto(url);
  const el = await page.$('#canvas');
  const out = path.join(process.cwd(), 'sample.png');
  await el.screenshot({ path: out });
  await browser.close();
  console.log('Sample image saved to', out);
}

sample();

